package com.community.backend.controller;

import com.community.backend.pojo.vo.ReportVO;
import com.community.backend.service.ReportService;
import com.community.backend.service.UserService;
import com.community.backend.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.relational.core.sql.In;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/report")
public class ReportController {
    // 营业额统计
    private final ReportService reportService;
    private final UserService userService;
    public ReportController(ReportService reportService, UserService userService) {
        this.reportService = reportService;
        this.userService = userService;
    }
    // 统计收入
    @GetMapping("/turnoverStatistics")
    public Result<ReportVO> statisticalIncome(
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate end) {
        log.info("营业额统计：{} - {}", begin, end);
        ReportVO reportVO = reportService.turnoverStatistics(begin, end,"已缴");
        return Result.success(reportVO);
    }
    // 营业额统计对比
    @GetMapping("/contrast")
    public Result<ReportVO> contrast(
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate end) {
        log.info("营业额统计：{} - {}", begin, end);
//        ReportVO okreportVO = reportService.turnoverStatistics(begin, end,"已缴");
        ReportVO NoreportVO = reportService.turnoverStatistics(begin, end,"未缴");
        return Result.success(NoreportVO);
    }



    //两小时在线用户
    @GetMapping("/onlineUser")
    public Result<List<Integer>> statisticsUsers(){
        log.info("开始统计用户");
        List<Integer> list = reportService.statisticsUsers();
        return Result.success(list);
    }



    @GetMapping("/fees")
    public Result<Map<String,Integer>> statisticsFees(){
        log.info("开始统计");
        Map<String,Integer> map = reportService.statisticsFees();
        return Result.success(map);
    }
}
